﻿//------------------------------------------------------------------------------
// Copyright © FRA & FV 2014
// All rights reserved
//------------------------------------------------------------------------------
// Binary Serialization SDK
//
// SVN revision information:
//   $Revision: 96 $
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;

namespace FRAFV.Binary.Serialization
{
	/// <summary>
	/// Binary strings extensions
	/// </summary>
	public static class BinText
	{
		/// <summary>
		/// Reads an array of strings from the stream till empty string.
		/// </summary>
		/// <param name="reader">Binary reader</param>
		/// <returns>The string array being read.</returns>
		public static string[] ReadMultiString(this BinaryReader reader)
		{
			var result = new List<string>();
			for (string s = reader.ReadString(); !String.IsNullOrEmpty(s); s = reader.ReadString())
				result.Add(s);
			return result.ToArray();
		}

		/// <summary>
		/// Writes an array of strings to the stream.
		/// </summary>
		/// <param name="writer">Binary writer</param>
		/// <param name="value">The string array being written.</param>
		public static void WriteMultiString(this BinaryWriter writer, string[] value)
		{
			foreach (string s in value)
				writer.Write(s);
			writer.Write("");
		}
	}
}
